<?php 
require_once('./admin/View/video/inc_admin.php'); 
 ?>
        <!--PAGE CONTENT -->
        <div id="content">

            <div class="inner" style="min-height:1200px;">
                <div class="row">
                    <div class="col-lg-12">
<?php 

//连接数据库

//编写sql语句
$sql="select vid,videoname,tid,uploaddate,pic from videos";
//关键字可能是用户点击搜索按钮得到的，也可能是点击“下一页”超链接得到的
if($_REQUEST['key'])
{
$key=trim($_REQUEST['key']);
$sql=$sql." where videoname like'%{$key}%'";
}
//获取总行数，用于计算分几页显示
$result=mysql_query($sql);
$totalrows=mysql_num_rows($result);
//获取指定的页码
$page=$_REQUEST['page'];
//判断是否指定第几页，如果没有指定，则显示第一页。
if(!isset($page))   $page=1;
//如果用户点击了搜索按钮，则页码也设置第一页
if($_POST['search']) $page=1;
//定义每页显示的行数
$rowsperpage=2;
//计算从表中第几行开始输出
$start=($page-1)*$rowsperpage;
//查询用户，从第$start行开始，共查询$rowsperpage行
$sql.=" limit {$start},{$rowsperpage}";
//echo $sql.'<br/>';
//执行sql语句
$result=mysql_query($sql)or die('查询失败！'.mysql_error());
 ?>


<marquee scrollamount="25">
<h3>视频信息列表</h3>
</marquee> 
 <table align="center" width="80%">
  <tr>
  <td align="left">
    <form method=post action="" class="navbar-search pull-left">
  <input type="text" name="key" class="search-query" placeholder="Search">
       <button type="submit" class="btn btn-info">搜索</button>
      <p></p>
    </form>
  </td>
  </tr>
 </table>
    
<div class="container-fluid col-sm-offset-2 col-md-8">
<table align="center" class="table table-striped">
 
  <tr class="success">
    <th>序号</th>
    <th>视频名称</th>
    <th>类别</th>
    <th>添加时间</th>
    <th>海报</th>
    <th>操作</th>
  </tr>
  
  <?php 
while ($row=mysql_fetch_assoc($result))
 {
  echo '<tr>';
  echo '<td>'.$row['vid'].'</td>';

  echo '<td>'.$row['videoname'].'</td>';
    switch ($row['tid']) 
  {
    case '1':$tid="电视剧";break;
    case '2':$tid="动漫";break;
    case '3':$tid="悬疑";break;
    case '4':$tid="惊悚";break;
    case '5':$tid="爱情";break;
    case '6':$tid="古装";break;
    case '7':$tid="都市";break;
    default:$tid="不知道";
  }
  echo '<td>'.$tid.'</td>';
    echo '<td>'.$row['uploaddate'].'</td>';
  echo '<td align="center"><img class="img-circle" src='.'upload/'.$row['pic'].' width=60 height=80></td>';
  
  echo  '<td><a href="index.php?c=video&m=videomod&id='.$row['vid'].'" class="btn btn-primary">修改</a>
   <a href="index.php?c=video&m=delete&id='.$row['vid'].'" onClick="return confirm(\'确定要删除吗？\');" class="btn btn-danger">删除</a></td>';
  echo '</tr>';
}
  echo '</table>';
   //计算总页数。如果每页显示的行数>总行数，则只有1页，否则，页数=总行数/每页行数，上取整。
//echo $rowsperpage.','.$totalrows;
  if($rowsperpage>=$totalrows)
    $totalpages=1;
  else
  {
    $totalpages=ceil($totalrows/$rowsperpage);
  }
//如果不是第1页，则显示第一页和上一页的链接，否则只显示文字
  echo "<nav>";
    echo "<ul class='pager'>";
    
    
 
  if($page>1)

  {   echo "<li><a href=?page=1&key={$key}>首页</a></li>";
    echo "<li><a href=?page=".($page-1)."&key={$key}>上一页</a></li>";
        //$first="<a href=?page=1&key={$key}>首页</a>";
    //$pre="<a href=?page=".($page-1)."&key={$key}>上一页</a>";
  }else
  {
    echo "<li class='disabled'><a href='#'>首页</a></li>";
    echo "<li class='disabled'><a href='#'>上一页</a></li>";
//$first='首页';
//$pre='上一页';
  }
  //如果不是最后一页，则显示下一页和最后一页的超链接，否则只显示文字
  if($page<$totalpages)
    {   
      
          echo "<li><a href=?page=".($page+1)."&key={$key}>下一页</a></li>";
          echo "<li><a href=?page=$totalpages&key={$key}>尾页</a></li>";
    //$last="<a href=?page=$totalpages&key={$key}>尾页</a>";
    //$next="<a href=?page=".($page+1)."&key={$key}>下一页</a>";
  }else
  {
    echo "<li class='disabled'><a href='#'>尾页</a></li>";
    echo "<li class='disabled'><a href='#'>下一页</a></li>";
    //$last='尾页';
    //$next='下一页';
  }

 echo "</ul>";
echo "</nav>";

   echo "<div class='text-center'>";
     echo "<ul class='pagination'>";
     echo "<li class='active'></li>";
  for($i=1;$i<=$totalpages;$i++)
  {       
     
     echo "<li><a class='num' href='?page=$i&key={$key}'>{$i}</a></li>";
 
  } 
  echo "<li><a class='next' href='?page=$i&key={$key}'>&gt;&gt;</a></li>";
  
  echo "<form method=post action='' class='form-search'>";
  echo "<tr><td><input type='text' name='page' placeholder='页码'' size=2 >";
  echo "<button type='submit' class='btn btn-info' >跳转</button></td></tr>";
  echo "</form>";
  
  echo "</ul>";
  echo "</div>";

  echo "<div class='text-right'>";
  echo "<table>";
  echo "<tr>共{$totalrows}条记录</tr>";
  echo "<td>&nbsp;&nbsp;$first"."&nbsp;&nbsp;"."$pre"."&nbsp;&nbsp;";
  echo "$next"."&nbsp;&nbsp;"."$last&nbsp;&nbsp";
  echo "</div>";
  //输出第几页/共几页
  echo "<font>";
  echo "<tr>&nbsp;&nbsp;&nbsp;第".$page."页/共".$totalpages."页</tr>";
  echo "&nbsp;&nbsp";
  echo "</font></td>";

  //输出转到几页的表单
  ?>

  
                   </table>
                   </div>
               </div>
                </div>
            </div>
         </div>
    
    <div id="footer">
    <p>&copy;  binarytheme &nbsp;2014 &nbsp;</p>
    </div>
    <script src="assets/plugins/jquery-2.0.3.min.js"></script>
    <script src="assets/plugins/bootstrap/js/bootstrap.min.js"></script>
    <script src="assets/plugins/modernizr-2.6.2-respond-1.1.0.min.js"></script>
</body>
</html>
